/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ys.usbreader;

import android.util.Log;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import android_serialport_api.Get_Root;

public class UsbReader
{
    public native String  stringFromJNI();

    /* This is another native method declaration that is *not*
     * implemented by 'hello-jni'. This is simply to show that
     * you can declare as many native methods in your Java code
     * as you want, their implementation is searched in the
     * currently loaded native libraries only the first time
     * you call them.
     *
     * Trying to call this function will result in a
     * java.lang.UnsatisfiedLinkError exception !
     */
    public native String  unimplementedStringFromJNI();

    /* this is used to load the 'hello-jni' library on application
     * startup. The library has already been unpacked into
     * /data/data/com.example.hellojni/lib/libhello-jni.so at
     * installation time by the package manager.
     */
    public static native String find();
    public static native int open();
    public static native void close();
    public static native String  getCardNo();

    private String mInputData;
    private String mUsbReader;


    public UsbReader() {

    }

    // Getters and setters
    public String getUsbReader() {
        mUsbReader = UsbReader.find();
        return mUsbReader;
    }

    // Getters and setters
    public String getInputData() {
        System.out.println("Hello usb reader");

        if ( mUsbReader != "" )  {
            //System.out.println("fd="+fd);
            mInputData = UsbReader.getCardNo();
            //UsbReader.close();
        } else {
            System.out.println("Usb Reader not found");
        }
        return mInputData;
    }
    static {
        System.loadLibrary("usbreader");
    }
    public static void main(String [] args){
        System.out.println("Hello usb reader");
        int fd = UsbReader.open();
        if ( fd > 0 )  { 
		System.out.println("fd="+fd);
		String cardNo = UsbReader.getCardNo();
		System.out.println("cardNo="+cardNo);
		UsbReader.close(); 
        } else { 
                System.out.println("Usb Reader not found");
        }
    }
}
